﻿Module dataFormaPago
    Private dtFormaPago As New DataTable

    Public Sub listaFormaPago()

        conectar()
        dtFormaPago.Clear()

        Cursor.Current = Cursors.WaitCursor
        cmd.Connection = con
        cmd.CommandText = "SELECT * FROM tformasdepago"
        cmd.CommandType = CommandType.Text
        da.SelectCommand = cmd
        da.Fill(dtFormaPago)
        'Çargamos el Datagridview
        With frmFormaPago.DGV_FormaPago

            .DefaultCellStyle.Font = New Font("Verdana", 10)
            .AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.DisplayedCells
            .AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.DisplayedCells
            .ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
            .AlternatingRowsDefaultCellStyle.BackColor = Color.AntiqueWhite

            .DataSource = dtFormaPago


            .Columns(0).ReadOnly = True
            .Columns(0).HeaderText = "Código"
            .Columns(1).HeaderText = "Nombre"
            .Refresh()
        End With

        'Coloreamos intercaladamente el datagridview



        Cursor.Current = Cursors.Default
        desconectar()



    End Sub


    Sub ingresaFormaPago(ByVal vNom As String)
        conectar()
        cmd = New Odbc.OdbcCommand("INSERT INTO tformasdepago (Nombre) Values('" + vNom + "')", con)
        If cmd.ExecuteNonQuery Then
            listaBlock()
        Else
            MessageBox.Show(msjNoIngresar, msjTituloModal, MessageBoxButtons.OK, MessageBoxIcon.Error)

        End If

        desconectar()

    End Sub


    Sub actualizaFormaPago(ByVal id As Integer, ByVal vNom As String)

        conectar()

        cmd = New Odbc.OdbcCommand("UPDATE tformasdepago set Nombre='" + vNom + "' WHERE ID = '" & id & "'", con)

        If cmd.ExecuteNonQuery Then
            listaBlock()
        Else
            MessageBox.Show(msjNoActualizar, msjTituloModal, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
        desconectar()


    End Sub


    Sub eliminaFormaPago(ByVal vID As Integer)

        conectar()

        cmd = New Odbc.OdbcCommand("DELETE FROM tformasdepago WHERE ID = '" & vID & "'", con)

        If cmd.ExecuteNonQuery Then
            listaBlock()
        Else
            MessageBox.Show(msjNoEliminar, msjTituloModal, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
        desconectar()


    End Sub
End Module
